<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ajaxhandler extends CI_Controller {

	public function index()
	{
             
	}
        
         public function getallskills(){
            $this->load->model('skills');// loading user model
            $result=$this->skills->getAllSkills();
            $resp=array();
            foreach($result as $r){
                $id = $r->id;
                $sn=$r->SKILL_NAME;
                array_push($resp, array('value'=>$id,'text'=>$sn));
            }
            echo json_encode($resp);
        }
        
        public function getalldegree(){
            $sql="SELECT * FROM edu_degree";
                  $result = $this->db->query($sql);
            $resp = array();
            if($result!=NULL){
                foreach($result->result() as $r){
                    $value = $r->id;
                    $text= $r->DEGREE_NAME;
                    array_push($resp,array('text'=>$text,'value'=>$value));
                }
            }
            echo json_encode($resp);
        }
        
        public function getallmajors(){
            $sql = "SELECT * FROM majors";
            $result = $this->db->query($sql);
            $resp = array();
            if($result!=NULL){
                foreach($result->result() as $r){
                    $value = $r->id;
                    $text= $r->MAJOR_NAME;
                    array_push($resp,array('text'=>$text,'value'=>$value));
                }
            }
            echo json_encode($resp);
            
        }
        public function getallschools(){
            $sql = "SELECT id, SCHOOL_NAME FROM schools";
            $result = $this->db->query($sql);
            $resp = array();
            if($result!=NULL){
                foreach($result->result() as $r){
                    $value = $r->id;
                    $text= $r->SCHOOL_NAME;
                    array_push($resp,array('text'=>$text,'value'=>$value));
                }
            }
            echo json_encode($resp);
        }
        
            public function getallcertificates(){
            $sql = "SELECT id, CERTIFICATES_NAME FROM certificates";
            $result = $this->db->query($sql);
            $resp = array();
            if($result!=NULL){
                foreach($result->result() as $r){
                    $value = $r->id;
                    $text= $r->CERTIFICATES_NAME;
                    array_push($resp,array('text'=>$text,'value'=>$value));
                }
            }
            echo json_encode($resp);
        }
        
        public function getproficiency(){
              $resp = array();
            for($i=1;$i<=10;$i++){
                array_push($resp, array('text'=>$i,'value'=>$i));
            }
            echo json_encode($resp);
        }
        
        public function getallskillnames(){
            $uid = $uid = $this->session->userdata("user_id");
            if($uid!=NULL){
            $sql = "SELECT DISTINCT master_skill.id, master_skill.SKILL_NAME FROM matches INNER JOIN master_skill ON matches.TO_TEACH_SKILL_ID = master_skill.id where matches.USER_LOGIN_ID =".$uid;
            $result = $this->db->query($sql);
            $resp = array();
            if($result!=NULL){
                foreach($result->result() as $name){
                    $skillid = $name->id;
                    $skillname= $name->SKILL_NAME;
                    array_push($resp,array('id'=>$skillid,'name'=>$skillname));
                }
             }
                 echo json_encode($resp);
          }
        }
}
